#include <bits\stdc++.h>
using namespace std;

class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        int n = nums.size();
        vector<int> f(n, 1);
        auto g = f;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) f[i] = max(g[j] + 1, f[i]);
                else if (nums[i] < nums[j]) g[i] = max(f[j] + 1, g[i]);
            }
        }
        return max(*max_element(f.begin(), f.end()), *max_element(g.begin(), g.end()));
    }
};